package com.ielts.fragment.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ielts.activity.R;
import com.ielts.model.IeltsItem;

public class IeltsAdapter extends BaseAdapter{
	Context context;
	ArrayList<IeltsItem> listData;
	
	public IeltsAdapter(Context context,ArrayList<IeltsItem> listItem) {
		this.context = context;
		this.listData = listItem;
	}
	@Override
	public int getCount() {
		return listData.size();
	}

	@Override
	public Object getItem(int position) {
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null){
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.layout_item_ielts, null);
			IeltsItemHolder holder = new IeltsItemHolder(convertView);
			convertView.setTag(holder);
		}
		IeltsItemHolder holder = (IeltsItemHolder)convertView.getTag();
		holder.setData(listData.get(position));
		return convertView;
	}
	class IeltsItemHolder{
		TextView month,date,content;
		ImageView more;
		public IeltsItemHolder(View parent) {
			month = (TextView)parent.findViewById(R.id.item_month);
			date = (TextView)parent.findViewById(R.id.item_date);
			content = (TextView)parent.findViewById(R.id.item_content);
			more = (ImageView)parent.findViewById(R.id.item_more);
		}
		public void setData(IeltsItem data){
			month.setText(data.month);
			date.setText(data.date);
			content.setText(data.content);
			more.setVisibility(data.buyed?View.INVISIBLE:View.VISIBLE);
			more.setTag(data.id);
		}
	}
}
